<template name="navbar">
	<view>
		<view class="content">
			<view class="navbar">
				<view class="nav-item" :class="{current: sortType == 0}" @click="tabClick(0)">
					综合
				</view>
				<view class="nav-item" :class="{current: sortType == 1}" @click="tabClick(1)">
					销量
				</view>
				<view class="nav-item" :class="{current: sortType == 2}" @click="tabClick(2)">
					新品
				</view>
				<view class="nav-item" :class="{current: sortType == 3}" @click="tabClick(3)">
					<text>价格</text>
					<view class="p-box">
						<text :class="{active: priceSort == 3 && sortType == 3}" class="yticon icon-shang"></text>
						<text :class="{active: priceSort == 4 && sortType == 3}" class="yticon icon-shang xia"></text>
					</view>
				</view>
				<image :src="icon.datu" v-if='listType == 1' @tap="tabClick(99)"></image>
				<image :src="icon.liebiao" v-else @tap="tabClick(99)"></image>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		props: {
			headerTop: {
				type: null,
				default: ''
			},
			headerPosition: {
				type: null,
				default: ''
			}
		},
		data() {
			return {
				icon:{
					datu:'/static/images/list/datu.png',
					liebiao:'/static/images/list/liebiao.png'
				},
				sortType: 0,
				priceSort: 0, //3 价格从低到高 4价格从高到低
				listType:0
			};
		},
		methods: {
			//筛选点击
			tabClick(index) {
				if (index == 99) {
					this.listType = this.listType == 0?1:0;
					var params = {
						listFlag: true,
						listType: this.listType
					};
					this.$emit('getAction', params);
					return;
				}else {
					
					this.sortType = index;
					if (index == 3) {
						if(this.priceSort == 3) {
							this.priceSort = 4;
						}else if(this.priceSort == 4) {
							this.priceSort = 3;
						}else {
							this.priceSort = 3;
						}
					}else {
						this.priceSort = 0;
					}
					
					var params = {
						sortFlag: true,
						sortType: this.sortType, 
						priceSort: this.priceSort
					};
					this.$emit('getAction', params);
				}
			}
		}
	}
</script>

<style lang="scss">
	page,
	.content {
		margin-bottom: 20rpx;
		background: #F5F5F5;
	}

	.content {
		// padding-top: 96upx;
		image{
			width: 44rpx;height: 44rpx;margin: 18rpx 38rpx 0 0;
		}
	}

	.navbar {
		// position: fixed;
		// left: 0;
		display: flex;
		width: 100%;
		height: 80upx;
		background: #fff;
		box-shadow: 0 2upx 10upx rgba(0, 0, 0, .06);
		z-index: 10;
		.nav-item {
			flex: 1;
			display: flex;
			justify-content: center;
			align-items: center;
			height: 100%;
			font-size: 26rpx !important;
			color: #666666;
			position: relative;

			&.current {
				color: #FE5E49;

				&:after {
					content: '';
					position: absolute;
					left: 50%;
					bottom: 0;
					transform: translateX(-50%);
					width: 120upx;
					height: 0;
				}
			}
		}

		.p-box {
			display: flex;
			flex-direction: column;

			.yticon {
				display: flex;
				align-items: center;
				justify-content: center;
				width: 30upx;
				height: 14upx;
				line-height: 1;
				margin-left: 4upx;
				font-size: 26upx;
				color: #888;

				&.active {
					color: $base-color;
				}
			}

			.xia {
				transform: scaleY(-1);
			}
		}

		.cate-item {
			display: flex;
			justify-content: center;
			align-items: center;
			height: 100%;
			width: 80upx;
			position: relative;
			font-size: 44upx;

			&:after {
				content: '';
				position: absolute;
				left: 0;
				top: 50%;
				transform: translateY(-50%);
				border-left: 1px solid #ddd;
				width: 0;
				height: 36upx;
			}
		}
	}

	/* 分类 */
	.cate-mask {
		position: fixed;
		left: 0;
		top: var(--window-top);
		bottom: 0;
		width: 100%;
		background: rgba(0, 0, 0, 0);
		z-index: 95;
		transition: .3s;

		.cate-content {
			width: 630upx;
			height: 100%;
			background: #fff;
			float: right;
			transform: translateX(100%);
			transition: .3s;
		}

		&.none {
			display: none;
		}

		&.show {
			background: rgba(0, 0, 0, .4);

			.cate-content {
				transform: translateX(0);
			}
		}
	}

	.cate-list {
		display: flex;
		flex-direction: column;
		height: 100%;

		.cate-item {
			display: flex;
			align-items: center;
			height: 90upx;
			padding-left: 30upx;
			font-size: 28upx;
			color: #555;
			position: relative;
		}

		.two {
			height: 64upx;
			color: #303133;
			font-size: 30upx;
			background: #f8f8f8;
		}

		.active {
			color: $base-color;
		}
	}

	/* 商品列表 */
	.goods-list {
		display: flex;
		flex-wrap: wrap;
		padding: 0 30upx;
		background: #fff;

		.goods-item {
			display: flex;
			flex-direction: column;
			width: 48%;
			padding-bottom: 40upx;

			&:nth-child(2n+1) {
				margin-right: 4%;
			}
		}

		.image-wrapper {
			width: 100%;
			height: 330upx;
			border-radius: 3px;
			overflow: hidden;

			image {
				width: 100%;
				height: 100%;
				opacity: 1;
			}
		}

		.title {
			font-size: $font-lg;
			color: $font-color-dark;
			line-height: 80upx;
		}

		.price-box {
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding-right: 10upx;
			font-size: 24upx;
			color: $font-color-light;
		}

		.price {
			font-size: $font-lg;
			color: $uni-color-primary;
			line-height: 1;

			&:before {
				content: '￥';
				font-size: 26upx;
			}
		}
	}

	.good_list {
		width: 690rpx;
		margin: 0 0 0 38rpx;
	}
</style>
